package com.atguigu.srb.core.controller.api;

import com.atguigu.srb.core.service.WxLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @Description:
 * @Author: Gavin
 * @Date: 7/10/2023 4:33 PM
 */
//微信登录和远程调用不存在跨域的问题,所以可以不加@CrossOrigin这个注解
//这里使用普通的@Controller注解,不使用@RestController,因为有重定向或者转发的存在
@Controller
@Api(tags = "微信登录模块")
// @Controller
@Slf4j
@RequestMapping("/api/core/wx")
public class ApiWxLoginController {
    @Resource
    private WxLoginService wxLoginService;
    @ApiOperation("微信登录")
    @GetMapping("login")
    public String wxLogin(HttpSession session){
        return wxLoginService.login(session);
    }
    @ApiOperation("微信登录的回调的controller")
    @GetMapping("callback")
    //code和state是微信登录授权成功之后,微信登录的sdk给我们回传回来的参数
    public String callback(String code, String state, HttpSession session, HttpServletRequest request){
        return wxLoginService.callback(code,state,session,request);
    }
}
